package blazingbubble.legacy;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.swing.JFrame;

import spark.utility.Clock;

public final class Main extends JFrame
{
	private static final long serialVersionUID = 17062219;

	private static Main instance = new Main();
	private static final String RESOURCE_PATH = "G:/My Projects/Java/Blazing Bubble/resources/";
	Scene scene;

	private Main()
	{
		super();
	}

	public void shutdown()
	{
		scene.shutdown();
	}

	public void execute(String[] args)
	{
		GLCapabilities glcaps = new GLCapabilities();
		GLCanvas canvas = new GLCanvas(glcaps);

		scene = new Scene();

		canvas.addGLEventListener(scene);
		this.addKeyListener(scene);
		canvas.addMouseMotionListener(scene);

		setTitle("Blazing Bubble");
		setSize(new Dimension(800, 600));

		getContentPane().add(canvas,BorderLayout.CENTER);

		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				shutdown();
				System.exit(0);
			}
		}

		);

		Clock.getInstance().reset();
		Clock.getInstance().update();

		setVisible(true);
		while(true)
			canvas.display();
	}

	public static Main getInstance() { return instance; }
	public static String getResourcePath() { return RESOURCE_PATH; }

	public static void main(String[] args)
	{
		instance.execute(args);
	}
}
